package my.dict.data;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Parse1 {
    //comment by john doe
	String stringLines;
	Map<String, String> mapWords = new LinkedHashMap<String, String>();
	List<String> words = new ArrayList<String>();
	String[] defs;
 	
	public Map<String, String> getMapWords() {
		return this.mapWords;
	}
	
	public Parse1() {		
		
		Source s1 = new Source("wordlist.txt");
		stringLines = s1.stringLines;	
		
		getDefs(stringLines);
		
		int num = words.size();
		System.out.println("Number of words: " + num);
		for(int i = 0; i < num; i++) {
			mapWords.put(words.get(i), defs[i+1]);			
		}
		
	}

	public void getDefs(String source) {
		String regDefs = "[A-Z][A-Z]+[: ]";
		Pattern splitPattern = Pattern.compile(regDefs);
		
		defs = splitPattern.split(source);	//get definitions
		
		Matcher wordMatcher = splitPattern.matcher(source);		//get words	
		while(wordMatcher.find()) {
			String aWord = wordMatcher.group().substring(0, (wordMatcher.group().length() - 1));
			words.add(aWord.toLowerCase());
		}	
		
	}

}